//
// Created by augtons on 2022/1/7.
//

#ifndef WINDSWING_MY_UDP_H
#define WINDSWING_MY_UDP_H

#include "esp_log.h"
#include "global_event.h"
#include "lwip/sockets.h"
#include "driver/gpio.h"
#include "wind_swing_command.h"
#include "windswing_specific.h"

#define WINDSWING_PORT_COMPUTER (9090)
#define WINDSWING_PORT_PHONE    (9091)

#define COMPUTER_RECV_TSAK_P    (2)
#define COMPUTER_RECV_TASK_S    (2048)
#define COMPUTER_SEND_TASK_P    (2)
#define COMPUTER_SEND_TASK_S    (2048)

#define PHONE_RECV_TASK_P       (2)
#define PHONE_RECV_TASK_S       (2048)
#define PHONE_SEND_TASK_P       (2)
#define PHONE_SEND_TASK_S       (2048)

/*==Remote IP Port==*/
struct sockaddr_in computerName;
struct sockaddr_in phoneName;

/*==Local IP Port==*/
struct sockaddr_in serviceName_computer;
struct sockaddr_in serviceName_phone;

/*==functions prototype==*/
void initUDPTaskManager();
void initUDPSockets();  //called in fn:initWifi();

void task_computer_create();
void task_computer_destroy();
void task_phone_create();
void task_phone_destroy();


/*==udp manager==*/
typedef struct {
    TaskHandle_t recv_handle;
    TaskHandle_t send_handle;
    int sock;
    void (*create)();
    void (*destroy)();
}UDPTaskManager;

UDPTaskManager computer_udp_manager;
UDPTaskManager phone_udp_manager;

/*==phone message==*/
QueueHandle_t phone_message_queue;
typedef struct {
    char msg[32];
}PhoneMessage;


/*==tasks==*/
_Noreturn void task_computer_recv(void *args);
_Noreturn void task_computer_send(void *args);

_Noreturn void task_phone_recv(void *args);
_Noreturn void task_phone_send(void *args);
#endif //WINDSWING_MY_UDP_H
